package com.zbkj.crmeb.plat.by.dto;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

public class Result {

	/**
	 * 处理结果，是否成功
	 */
	private boolean success;

	/**
	 * 处理返回码
	 */
	private String code;

	/**
	 * 结果处理描述
	 */
	private String message;

	/**
	 * 结果包含数据
	 */
	private Object data;

	/**
	 * key/value结果;流程引擎依赖的变量variables
	 */
	private Map<String, Object> context;

	/**
	 * 事务回调函数
	 */
	private Function<Object, Result> transCallback;

	public Result() {
		this.context = new HashMap<String, Object>();
	}

	public Result(boolean success) {
		this.success = success;
		this.context = new HashMap<String, Object>();
	}

	public Result(boolean success, String code, String message) {
		this.success = success;
		this.code = code;
		this.message = message;
		this.context = new HashMap<String, Object>();
	}

	public Result(boolean success, String code, String message, Object data) {
		this.success = success;
		this.code = code;
		this.message = message;
		this.data = data;
		this.context = new HashMap<String, Object>();
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Function<Object, Result> getTransCallback() {
		return transCallback;
	}

	public void setTransCallback(Function<Object, Result> transCallback) {
		this.transCallback = transCallback;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public Map<String, Object> getContext() {
		return context;
	}

	public void setContext(Map<String, Object> context) {
		this.context = context;
	}

	public void put(String key, Object value) {
		this.context.put(key, value);
	}

	public Object get(String key) {
		return this.context.get(key);
	}

	public static Result getFailureResult(String errorCode, String errorMsg) {
		return new Result(Boolean.FALSE, errorCode, errorMsg);
	}
	public static Result getSuccessResult() {
		return new Result(Boolean.TRUE, (String)null, (String)null);
	}

	public static Result getSuccessResult(Object data) {
		return new Result(Boolean.TRUE, (String)null, (String)null,data);
	}

}